var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabIndex: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  backto: function (e) {
    wx.navigateBack({})
  },
  onLoad: function (options) {
    var t = this
    t.setData({
      options:options
    })
    setTimeout(function(){
      t.validate();
    },500)
  },
  validate:function(e){
    let that = this;
    that.getInfo();
    var options = that.data.options;
    var scene = decodeURIComponent(options.scene)
    if (scene != "undefined") {
      var post_data = {};
      post_data.openid = app.globalData.openid;
      post_data.out_trade_no = scene;
      post_data.type = 'getInfo';
      app.ihttpPost("https://www.58zltc.com/api.php/ShopAdmin/validate", post_data, function (res) {
        if (res.data.err_code == 400) {
          app.iModel(res.data.err_msg);
        } else {
          wx.showModal({
            title: '提示',
            content: '确定验证该订单？',
            success: function (res) {
              if (res.confirm) {
                post_data.type = 'validate';
                app.ihttpPost("https://www.58zltc.com/api.php/ShopAdmin/validate", post_data, function (res) {
                  app.iModel(res.data.err_msg);
                  if (res.data.err_code === 0) {
                    that.getInfo();
                  }
                })
              }
            }
          })
        }
      })
    } else {
      that.getInfo();
    }
  },
  getInfo: function(){
    let that = this;
    wx.showLoading({
      title: '数据加载中…',
    })
    console.log(app.globalData.openid);
    app.ihttpGet("https://www.58zltc.com/api.php/ShopAdmin/validateCenter/openid/" + app.globalData.openid, function (res) {
      if (res.data.err_code == 400) {
        app.iModel(res.data.err_msg);
      } else {
        that.setData({
          info: res.data.data.shop,
          list: res.data.data.list,
          tabs: res.data.data.tabs,
        })
      }
    })
    app.ihttpGet("https://www.58zltc.com/api.php/ShopAdmin/validateCoupon/openid/" + app.globalData.openid, function (res) {
      if (res.data.err_code == 400) {
        app.iModel(res.data.err_msg);
      } else {
        that.setData({
          couPon: res.data
        })
      }
    })
  },
  setTab: function(e){
    const idx = e.currentTarget.dataset.index;
    this.setData({
      tabIndex: idx
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },
})